package qky.api.service.impl;

import org.springframework.stereotype.Component;
import java.util.Map;
import java.util.List;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import qky.common.utils.PageUtils;
import qky.common.utils.Query;
import org.springframework.beans.factory.annotation.Autowired;

import qky.api.dao.TokenDao;
import qky.api.entity.TokenEntity;
import qky.api.service.TokenService;


@Component
public abstract class TokenServiceImplGen implements TokenService {

    @Autowired
    protected TokenDao dao;

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<TokenEntity> page = this.dao.selectPage(
                new Query<TokenEntity>().getPage(params),
                new QueryWrapper<TokenEntity>()
        );

        return new PageUtils(page);
    }

    @Override
    public TokenEntity query(String id) {
        return dao.selectById(id);
    }

    @Override
    public List<TokenEntity> queryList(Map<String, Object> params) {
        return dao.queryList(params);
    }

    @Override
    public Boolean save(TokenEntity entity) {
        return dao.insert(entity) > 0;
    }

    @Override
    public Boolean saveBatch(List<TokenEntity> list) {
        int size = list.size();
        for (TokenEntity entity : list) {
            size -= dao.insert(entity);
        }
        return size <= 0;
    }

    @Override
    public Boolean update(TokenEntity entity) {
        return dao.updateById(entity) > 0;
    }

    @Override
    public Boolean updateBatch(List<TokenEntity> list) {
        int size = list.size();
        for (TokenEntity entity : list) {
            size -= dao.updateById(entity);
        }
        return size <= 0;
    }

    @Override
    public Boolean delete(List<String> id) {
        return dao.deleteBatchIds(id) == id.size();
    }

}
